$(function () {
    findAll();
});

/**
 * 用Ajax从后台拿到数据然后赋值给页面
 */
function findAll() {
    let result = myAjax("/home", {}, "get");
    setDataCompany(result.companyModel);
    setNavFirstData(result.navModelList);
    setNavSecondData(result.navModelList);
    setNavProductData(result.navModelList);
    setNavWebsiteData(result.navModelList);
    setNavExampleData(result.navModelList);
    setNavNewsData(result.navModelList);
    setHrModelListData(result.hrModelList);
    setProductImgData(result.productModelList);
    setNewsInFoOneData(result.newsModelList);
    setNewsInFoTwoData(result.newsModelList);
    setNewsInFoThreeData(result.newsModelList);
    setConsultingData(result.consultingModelList);
    setOnlineData(result.onlineModelList);
    console.log(result);
}

function setDataCompany(data) {
    $("#logo").attr('src', URI + '/propertyimg' + data.logo);
    $("#companyName").html(data.name);
    $("#qrCodeIndex").attr("src", URI + '/propertyimg' + data.qrCodeIndex);
    $("#qrCodeIndexTitle").html(data.qrCodeIndexTitle);
    $("#qrCodeWeiXin").attr("src", URI + '/propertyimg' + data.qrCodeWeiXin);
    $("#qrCodeWeiXinTitle").html(data.qrCodeWeiXinTitle);
    $("#recordMessage").html(data.recordMessage);
    $("#recordNumber").html(data.recordNumber);
    // $("#address").html(data.address);
    // $("#addressImg").attr("src", data.addressImg);
    // $("#phone").html(data.phone);
    // $("#phoneImg").attr(data.phoneImg);
    // $("#email").html(data.email);
    // $("#emailImg").attr(data.emailImg);
    $("#nickName").html(data.nickName);
    $("#tag").html(data.tag);
    $("#companyContent").html(data.content);
}

/***
 * 一级导航
 * @param data
 */
function setNavFirstData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].typeName === "一级导航") {
            html += "<a href=" + URI +data[i].href + "><div>" + data[i].name + "</div></a>";
        }
    }
    $("#firsNav").html(html);

}

/**
 * 二级导航
 * @param data
 */
function setNavSecondData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].typeName === "二级导航") {
            html += "<div><a href=" +URI + data[i].href + ">" + data[i].name + "</a></div>";
        }
    }
    $("#secondNav").html(html);
}

/**
 * 产品导航
 */
function setNavProductData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].typeName === "产品导航") {
            html += "<div>\n" +
                "                <div><img src=" + URI + '/propertyimg' + data[i].img + "></div>\n" +
                "                <div>" + data[i].name + "</div>\n" +
                "            </div>";
        }
    }
    $("#productNav").html(html);
}

/**
 * 人力资源模块
 * @param data
 */
function setHrModelListData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += "<div>\n" +
            "            <div><a href=" + URI+ data[i].href + "><img src=" + URI + '/propertyimg' +data[i].img + "></a></div>\n" +
            "            <div>" + data[i].title + "</div>\n" +
            "            <div></div>\n" +
            "            <div>" + data[i].contentOne + "</div>\n" +
            "            <div>" + data[i].contentTwo + "</div>\n" +
            "        </div>";
    }
    $("#hrList").html(html);
}

/**
 * 产品图片
 * @param data
 */
function setProductImgData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].houseName === "住宅地产") {
            html += " <div><img src=" + URI + '/propertyimg' +data[i].img + "></div>";
        }
    }
    $("#productImg").html(html);

}

/**
 * 第三方网站导航
 */
function setNavWebsiteData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].typeName === "第三方网站导航") {
            html += "<div><img src=" + URI + '/propertyimg' +data[i].img + "></div>";
        }
    }
    $("#websiteNav").html(html);
}

function setNavExampleData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].name === "精品案例") {
            html += "<div>" + data[i].name + "</div>\n" +
                "            <div><img src=" + URI + '/propertyimg' +data[i].img + "></div>";
        }
    }
    $("#example").html(html);
}

function setNavNewsData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].typeName === "新闻导航") {
            html += "<div>" + data[i].name + "</div>\n" +
                "            <div><img src=" + URI + '/propertyimg' +data[i].img + "></div>";
        }
    }
    $("#newsExample").html(html);
}

/**
 * 新闻信息
 */
function setNewsInFoOneData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].id === 13) {
            html += "<div>" + data[i].title + "</div>\n" +
                "                <div>" + data[i].updateTime + "</div>\n" +
                "                <div>" + data[i].content + "</div>\n" +
                "                <div>\n" +
                "                    <div onclick='toNewsPage()'>" + data[i].typeName + "</div>\n" +
                "                </div>";
        }


    }
    $("#newsInfoOne").html(html);
}

function setNewsInFoTwoData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].id === 15) {
            html += "<div>" + data[i].title + "</div>\n" +
                "                <div>" + data[i].updateTime + "</div>\n" +
                "                <div>" + data[i].content + "</div>\n" +
                "                <div>\n" +
                "                    <div onclick='toNewsPage()'>" + data[i].typeName + "</div>\n" +
                "                </div>";
        }

    }
    $("#newsInfoTwo").html(html);
}

function setNewsInFoThreeData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].id === 10) {
            html += "<div>" + data[i].title + "</div>\n" +
                "                <div>" + data[i].updateTime + "</div>\n" +
                "                <div>" + data[i].content + "</div>\n" +
                "                <div>\n" +
                "                    <div onclick='toNewsPage()'>" + data[i].typeName + "</div>\n" +
                "                </div>";
        }

    }
    $("#newsInfoThree").html(html);
}

/**
 *
 */
function setConsultingData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += "<div>" + data[i].content + "</div>";
    }
    $("#consulting").html(html);
}

/**
 * Online
 */
function setOnlineData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += "<div>" + data[i].content + "</div>";
    }
    $("#online").html(html);
}

function toNewsPage() {
    window.open("/step-seven-xadmin/index/news.html","_self")
}